@layout("/common/_container.html"){
<div class="ibox float-e-margins">
<style>
	input{
	 width:100%;
	}
	select{
	width:100%;
	height:100%;
	}
	</style>
    <div>
        <div class="form-horizontal" style='overflow:scroll;'>

           
            <input type="hidden" id="paymentMethodValue" value="${item.receiveBasicInformation.receivePaymentMethod}"> <!-- 付款方式值的临时存放 -->
            <input type="hidden" id="iscollectMoneyValue" value="${item.receiveBasicInformation.receiveIscollectMoney}"> <!-- 是否代收货款值的临时存放 -->
            <input type="hidden" id="shippingMethodValue" value="${item.receiveBasicInformation.receiveShippingMethod}" ><!-- 送货方式值的临时存放 -->
            <input type="hidden" id="isinformDeliver" value="${item.receiveBasicInformation.receiveIsinformDeliver}" ><!-- 是否听通知发货值的临时存放 -->

            <!--  记录是否通过下拉框选择的值，如果值不为空，则不进行反写数据库的操作，如果值为空，则进行反写数据库的操作 -->
			<input type="hidden" id="consignerID" name="consignerID" value="yes">
			<input type="hidden" id="consigneeID" name="consigneeID" value="yes">
			<div>
			<form id="receiveContract">
				 <input type="hidden" id="id" name="id" value="${item.receiveBasicInformation.id}">
				<table border="1" cellpadding="4px">
					<tr>
						<td>基本信息：</td>
						<td colspan="7"></td>
					</tr>
					<tr>
						<td>合同号:</td>
						<td><input id="receiveContractNumber" name="receiveContractNumber" type="text" value="${item.receiveBasicInformation.receive_contract_number}" readonly="readonly" style="background-color:#eee"/></td>
						<td>起运日期:</td>
						<td><input id="receiveStartDate" name="receiveStartDate"  value="${tool.dateType(item.receiveBasicInformation.receive_start_date)}"   onclick="laydate({istime: false, format: 'YYYY-MM-DD'})"/></td>
						<td>到货日期:</td>
						<td><input id="receiveArrivalDate" name="receiveArrivalDate"  value="${tool.dateType(item.receiveBasicInformation.receive_arrival_date)}"  onclick="laydate({istime: false, format: 'YYYY-MM-DD'})"/></td>
						<td>制单员:</td>
						<td><input id="receiveTradePerson" name="receiveTradePerson" value="${item.receiveBasicInformation.receive_trade_person}" readonly="readonly" type="text" style="background-color:#eee"/></td>
					</tr>
					<tr>
						<td>发货人:</td>
						<td><input id="receiveConsigner" name="receiveConsigner" value="${item.receiveBasicInformation.receiveConsigner}" type="text"/></td>
						 <!-- 发货人的下拉选择框 -->
           				 <div id="showConsigner" class="menuContent"
			                 style="display: none; position: absolute; z-index: 200;">
			                <ul id="show-Consigner" class="ztree tree-box" style="width: 200px !important;">
			                </ul>
			            </div>
						<td>发货人电话：</td>
						<td><input id="receiveConsignerTell" name="receiveConsignerTell" value="${item.receiveBasicInformation.receiveConsignerTell}" readonly="readonly" style="background-color:#eee" type="text"/></td>
						<td>发货人地址：</td>
						<td colspan="3"><input id="receiveConsignerPlace" name="receiveConsignerPlace"  value="${item.receiveBasicInformation.receiveConsignerPlace}" readonly="readonly" style="background-color:#eee" type="text"/></td>
					</tr>
					<tr>
						<td>收货人:</td>
						<td><input id="receiveConsignee" name="receiveConsignee"  value="${item.receiveBasicInformation.receiveConsignee}"  type="text"/></td>
						<!-- 收货人的下拉选择框 -->
           				 <div id="showConsignee" class="menuContent"
			                 style="display: none; position: absolute; z-index: 200;">
			                <ul id="show-Consignee" class="ztree tree-box" style="width: 200px !important;">
			                </ul>
			            </div>
						<td>收货人电话：</td>
						<td><input id="receiveConsigneeTell" name="receiveConsigneeTell"  value="${item.receiveBasicInformation.receiveConsigneeTell}"  readonly="readonly" style="background-color:#eee" type="text"/></td>
						<td>收货人地址：</td>
						<td colspan="3"><input id="receiveConsigneePlace" name="receiveConsigneePlace"   value="${item.receiveBasicInformation.receiveConsigneePlace}"  readonly="readonly" style="background-color:#eee" type="text"/></td>
					</tr>
					<tr>
						<td>付款方式:</td>
						<td><select id="receivePaymentMethod" name="receivePaymentMethod">
							  <option value ="回付" selected>回付</option>
							  <option value ="到付">到付</option>
							</select>
						</td>
						<td>总运费：</td>
						<td><input id="receiveGrossFreight" name="receiveGrossFreight" value="${item.receiveBasicInformation.receive_gross_freight}" type="text" readonly="readonly" style="background-color:#eee"/></td>
						<td>总信息费：</td>
						<td><input id="receiveGrossMessagefee" name="receiveGrossMessagefee"   value="${item.receiveBasicInformation.receive_gross_messagefee}" type="text" readonly="readonly" style="background-color:#eee"/></td>
						<td>总提货费：</td>
						<td><input id="receiveGrossPickupCharge" name="receiveGrossPickupCharge"   value="${item.receiveBasicInformation.receive_gross_pickup_charge}"  readonly="readonly" type="text" readonly="readonly" style="background-color:#eee"/></td>
					</tr>
					<tr>
						<td>是否代收货款:</td>
						<td><select id="receiveIscollectMoney" name="receiveIscollectMoney">
							  <option value ="否" selected>否</option>
							  <option value ="是">是</option>
							</select>
						</td>
						<td>送货方式：</td>
						<td><select id="receiveShippingMethod" name="receiveShippingMethod">
							  <option value ="送到">送到</option>
							  <option value ="自提">自提</option>
							</select></td>
						<td>是否听通知发货：</td>
						<td colspan="3"><select id="receiveIsinformDeliver" name="receiveIsinformDeliver">
							  <option value ="否" selected>否</option>
							  <option value ="是">是</option>
							</select></td>
					</tr>
					<tr>
						<td>备注：</td>
						<td colspan="7"><input id="receiveRemark" name="receiveRemark" type="text" value="${item.receiveBasicInformation.receiveRemark}"/></td>
					</tr>
				</table>
			</form>
			</div>
			<button type="button" onclick="funTr()">增加货物</button>
			<div style='width:1250px;'>
			<form id="goodsInfo">
				<table border="1" cellpadding="4px" width="1200px" class="table1">
					<tr>
						<td colspan="14">货物信息</td>
					</tr>
					<tr>
						<td width="50px">序号</td>
						<td width="170px">货物编号</td>
						<td width="250px">货物名称</td>
						<td width="250px">货物规格</td>
						<td width="100px">包装方式</td>
						<td width="90px">数量（件）</td>
						<td width="90px">重量（KG）</td>
						<td width="90px">体积（m³）</td>
						<td width="70px">运费</td>
						<td width="70px">信息费</td>
						<td width="70px">提货费</td>
						<td width="120px">仓库</td>
						<td width="130px">备注</td>
						<td width="80px">操作</td>
					</tr>
					 @for(receiveGoodsInformation   in   item.receiveGoodsInformations){ 
 							
					<tr id="a">
						<td class="id">${receiveGoodsInformationLP.index}</td>
						<input id="goodsID" type="hidden" name="goodsID" value="${receiveGoodsInformation.id}"></input>
						<td><input id="receiveGoodsId" name="receiveGoodsId" type="text" value="${receiveGoodsInformation.receiveGoodsId}" readonly="readonly" style="background-color:#eee"/></td>
						<td><input id="receiveGoodsName" name="receiveGoodsName"  value="${receiveGoodsInformation.receiveGoodsName}" readonly="readonly" style="background-color:#eee" type="text"/></td>
						<td><input id="receiveGoodsModel" name="receiveGoodsModel" value="${receiveGoodsInformation.receiveGoodsModel}" readonly="readonly" style="background-color:#eee" type="text"/></td>
						<td><select id="receiveGoodsPackage" name="receiveGoodsPackage" >
								<option value="">请选择</option>
							  <option value="无包装">无包装</option>
                            	<option value="纸箱装">纸箱装</option>
                            	<option value="木箱装">木箱装</option>
                            	<option value="袋装">袋装</option>
                            	<option value="铁桶装">铁桶装</option>
                            	<option value="塑料桶装">塑料桶装</option>
                            	<option value="托盘装">托盘装</option>
                            	<option value="散装">散装</option>
                            	<option value="直桶装">直桶装</option>
							</select>
							<input type="hidden" id="goodsPackage" value="${receiveGoodsInformation.receiveGoodsPackage}" ><!-- 仓库信息的临时存放 -->
							</td>
						<td><input id="receiveGoodsQuantity" name="receiveGoodsQuantity" value="${receiveGoodsInformation.receiveGoodsQuantity}" onkeyup="value=value.replace(/[^\-?\d.]/g,'')"/></td>
						<td><input id="receiveGoodsWeight" name="receiveGoodsWeight" value="${receiveGoodsInformation.receiveGoodsWeight}" type="text"  onkeyup="value=value.replace(/[^\-?\d.]/g,'')"/></td>
						<td><input id="receiveGoodsVolume" name="receiveGoodsVolume" value="${receiveGoodsInformation.receiveGoodsVolume}" type="text"  onkeyup="value=value.replace(/[^\-?\d.]/g,'')"/></td>
						<td><input id="receiveGoodsFreight" name="receiveGoodsFreight" value="${receiveGoodsInformation.receiveGoodsFreight}"  type="text"  onkeyup="value=value.replace(/[^\-?\d.]/g,'')"/></td>
						<td><input id="receiveGoodsMessagefee" name="receiveGoodsMessagefee"  value="${receiveGoodsInformation.receiveGoodsMessagefee}" type="text"  onkeyup="value=value.replace(/[^\-?\d.]/g,'')"/></td>
						<td><input id="receiveGoodsPickupCharge" name="receiveGoodsPickupCharge" value="${receiveGoodsInformation.receiveGoodsPickupCharge}" type="text"  onkeyup="value=value.replace(/[^\-?\d.]/g,'')"/></td>
						<td><select id="receiveGoodsWarehouseName" name="receiveGoodsWarehouseName">
							<option value="">请选择</option>
                            @for(warehouse   in   warehouses){ 
                            	<option value="${warehouse.warehouseName}">${warehouse.warehouseName}</option>
 							@}
							</select>
							<input type="hidden" id="goodsWarehouseName" value="${receiveGoodsInformation.receiveGoodsWarehouseName}" ><!-- 仓库信息的临时存放 -->
							</td>
						<td><input id="receiveGoodsRemark" name="receiveGoodsRemark"  value="${receiveGoodsInformation.receiveGoodsRemark}" type="text"/></td>
						<td><button type="button" onclick="del(this);" >删除</button></td>
						<input id="id" type="hidden" name="id" value="${receiveGoodsInformation.id}"/>
					</tr>
					@}
					<tr id="sumCopy">
						<td colspan="5">总计</td>
						<td id="1"></td>
						<td id="2"></td>
						<td id="3"></td>
						<td id="goodsFreight"></td>
						<td id="goodsMessagefee"></td>
						<td id="goodsPickupCharge"></td>
						<td colspan="3"></td>
					</tr>
				</table>
				</form>
				
						<!-- 商品名的下拉选择框 -->
           				 <div id="showGoods" class="menuContent"
			                 style="display: none; position: absolute; z-index: 200;">
			                <ul id="show-Goods" class="ztree tree-box" style="width: 200px !important;">
			                </ul>
			            </div>
			</div>
            <div class="row btn-group-m-t">
                <div class="col-sm-10">
                    <#button btnCss="info" name="提交" id="ensure" icon="fa-check" clickFun="ReceiveBasicInformationInfoDlg.editSubmit()"/>
                    <#button btnCss="danger" name="取消" id="cancel" icon="fa-eraser" clickFun="ReceiveBasicInformationInfoDlg.close()"/>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="${ctxPath}/static/modular/system/receiveBasicInformation/receiveBasicInformation_info.js"></script>
<script>
//初始化付款方式选项
$("#receivePaymentMethod").val($("#paymentMethodValue").val());
//初始化是否代收货款选项
$("#receiveIscollectMoney").val($("#iscollectMoneyValue").val());
//初始化送货方式选项
$("#receiveShippingMethod").val($("#shippingMethodValue").val());
//初始化是否听通知发货选项
$("#receiveIsinformDeliver").val($("#isinformDeliver").val());

//初始化仓库、包装方式选项
$("select[name='receiveGoodsPackage']").each(function(){
	$(this).val($(this).siblings().eq(0).val());
})
$("select[name='receiveGoodsWarehouseName']").each(function(){
	$(this).val($(this).siblings().eq(0).val());
})

var i = 1;
$(".id").each(function(){
    $(this).html(i++);
});

function funTr(){
	//删除最后一个统计的节点
	$("#sumCopy").remove();
	
    var $td = $("#a").clone();       //增加一行,克隆第一个对象
  	$(".table1").append($td);
    var i = 1;
    $(".id").each(function(){       //增加一行后重新更新序号1,2,3......
    $(this).html(i++);
    })
    var thisTr = $td;
    thisTr.find(":input").val('');   //将尾行元素克隆来的保存的值清空
    thisTr.find(":input").eq(2).removeAttr("readOnly");
    thisTr.find(":input").eq(3).removeAttr("readOnly");
    thisTr.find(":input").eq(2).css('background-color','');
    thisTr.find(":input").eq(3).css('background-color','');
    $(".table1").append("<tr id='sumCopy'><td colspan='5'>总计</td><td id='1'></td><td id='2'></td><td id='3'></td><td id='goodsFreight'></td><td id='goodsMessagefee'></td><td id='goodsPickupCharge'></td><td colspan='3'></td></tr>");
    	$.ajax({
        url: Feng.ctxPath + '/goods/getgoodsid', 
        type: "get",
        dataType:"json",
        success:function(data){
        	thisTr.find(":input").eq(1).val(data);
        },
        error:function(){
        	alert("请求货物编号失败，刷新后再试！")
        }
        }); 
}

function del(obj){
	var tr1 = $(obj).parent().parent().parent().children().length;
	if(tr1 == 4){
		alert("货物信息不可为空！")
	}else{
		var a =  $(obj).parent().parent().children().eq(15).val();
		if(a!= undefined && a!=""){
			$.ajax({
				async : false,
				type : 'post',
				url : Feng.ctxPath+'/receiveBasicInformation/deleteedit?id='+a,
				contentType : "application/json;charset=UTF-8",
				success : function(data) {
					if (data == 'SUCCESS') {
						$(obj).parent().parent().remove();
					} else {
						 alert("删除失败!该收货登记已经通过审核，请刷新页面重试！");
						  window.parent.ReceiveBasicInformation.table.refresh();
						  ReceiveBasicInformationInfoDlg.close();
					}
				},
				error : function(data) {
					 Feng.error("删除失败!");
				}
			});
		}else{
			$(obj).parent().parent().remove();
		}
	}
	var i = 1;
	$(".id").each(function(){
	    $(this).html(i++);
	});
	initCount();
}

//非负浮点数
var re = /^\d+(\.\d+)?$/ ;

function testRe(re, s){ // 参数说明 re 为正则表达式 s 为要判断的字符 
	return re.test(s) 
} 

//总运费的动态计算
$("body").on("keyup","[name='receiveGoodsFreight']",function(){  
	var fee = 0;
	//判断是否通过验证，如果通过验证，则test保持不变，否则test为1
	var test1 = 0;
	$("input[name='receiveGoodsFreight']").each(function(){
		var a ;
		if($(this).val()==""){
			a=0;
		}else{
			a=Number($(this).val());
		}
		if(testRe(re,a)){
        	fee += a;
		}else{
			test1 = 1;
			alert("运费值只能包括数字和小数点，不要出现其他字符！");
			$(this).val("");
		}
	});
	
	if(test1==0){
		$("#goodsFreight").html(fee);
		$("#receiveGrossFreight").val(fee);
	}else{
		$("#goodsFreight").html("");
		$("#receiveGrossFreight").val("");
	}
});  

//总信息费的动态计算
$("body").on("keyup","[name='receiveGoodsMessagefee']",function(){  
	var fee = 0;
	var test1 = 0;
	$("input[name='receiveGoodsMessagefee']").each(function(){
		var a ;
		if($(this).val()==""){
			a=0;
		}else{
			a=Number($(this).val());
		}
		if(testRe(re,a)){
        	fee += a;
		}else{
			test1 = 1;
			alert("信息费只能包括数字和小数点，不要出现其他字符！");
			$(this).val("");
		}
	});
	
	if(test1==0){
		$("#goodsMessagefee").html(fee);
		$("#receiveGrossMessagefee").val(fee);
	}else{
		$("#goodsMessagefee").html("");
		$("#receiveGrossMessagefee").val("");
	}
}); 

//总提货费的动态计算
$("body").on("keyup","[name='receiveGoodsPickupCharge']",function(){  
	var fee = 0;
	var test1 = 0;
	$("input[name='receiveGoodsPickupCharge']").each(function(){
		var a ;
		if($(this).val()==""){
			a=0;
		}else{
			a=Number($(this).val());
		}
		if(testRe(re,a)){
        	fee += a;
		}else{
			test1 = 1;
			alert("提货费只能包括数字和小数点，不要出现其他字符！");
			$(this).val("");
		}
	});
	
	if(test1==0){
		$("#goodsPickupCharge").html(fee);
		$("#receiveGrossPickupCharge").val(fee);
	}else{
		$("#goodsPickupCharge").html("");
		$("#receiveGrossPickupCharge").val("");
	}
}); 

//总数量的动态计算
$("body").on("keyup","[name='receiveGoodsQuantity']",function(){  
	var fee = 0;
	var test1 = 0;
	$("input[name='receiveGoodsQuantity']").each(function(){
		var a ;
		if($(this).val()==""){
			a=0;
		}else{
			a=Number($(this).val());
		}
		if(testRe(re,a)){
        	fee += a;
		}else{
			test1 = 1;
			alert("总数量只能包括数字,不要出现其他字符！");
			$(this).val("");
		}
	});
	
	if(test1==0){
		$("#1").html(fee);
	}else{
		$("#1").html("");
	}
}); 

//总重量的动态计算
$("body").on("keyup","[name='receiveGoodsWeight']",function(){  
	var fee = 0;
	var test1 = 0;
	$("input[name='receiveGoodsWeight']").each(function(){
		var a ;
		if($(this).val()==""){
			a=0;
		}else{
			a=Number($(this).val());
		}
		if(testRe(re,a)){
        	fee += a;
		}else{
			test1 = 1;
			alert("总重量只能包括数字,不要出现其他字符！");
			$(this).val("");
		}
	});
	
	if(test1==0){
		$("#2").html(fee);
	}else{
		$("#2").html("");
	}
}); 

//总体积的动态计算
$("body").on("keyup","[name='receiveGoodsVolume']",function(){  
	var fee = 0;
	var test1 = 0;
	$("input[name='receiveGoodsVolume']").each(function(){
		var a ;
		if($(this).val()==""){
			a=0;
		}else{
			a=Number($(this).val());
		}
		if(testRe(re,a)){
        	fee += a;
		}else{
			test1 = 1;
			alert("总重量只能包括数字,不要出现其他字符！");
			$(this).val("");
		}
	});
	
	if(test1==0){
		$("#3").html(fee);
	}else{
		$("#3").html("");
	}
}); 
function initCount(){
	//初始化运费、信息费、提货费
	var a = 0;
	$("input[name='receiveGoodsFreight']").each(function(){
		var count ;
		count=Number($(this).val());
        	a += count;
	});
	$("#goodsFreight").text(a);
	$("#receiveGrossFreight").val(a);
	
	var b = 0;
	$("input[name='receiveGoodsMessagefee']").each(function(){
		var count ;
		count=Number($(this).val());
        	b += count;
	});
	$("#goodsMessagefee").text(b);
	$("#receiveGrossMessagefee").val(b);
	
	var c = 0;
	$("input[name='receiveGoodsPickupCharge']").each(function(){
		var count ;
		count=Number($(this).val());
        	c += count;
	});
	$("#goodsPickupCharge").text(c);
	$("#receiveGrossMessagefee").val(c);
	
	var d = 0;
	$("input[name='receiveGoodsQuantity']").each(function(){
		var count ;
		count=Number($(this).val());
        	d += count;
	});
	$("#1").text(d);
	
	var e = 0;
	$("input[name='receiveGoodsWeight']").each(function(){
		var count ;
		count=Number($(this).val());
        	e += count;
	});
	$("#2").text(e);
	
	var f = 0;
	$("input[name='receiveGoodsVolume']").each(function(){
		var count ;
		count=Number($(this).val());
        	f += count;
	});
	$("#3").text(f);
}
$(function(){
	initCount();
});
</script>
@}
